package com.car.advertising.activity.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.car.advertising.R;
import com.car.advertising.entity.HomeDataEntity;
import com.support.widget.interfacelistener.OnRecyclerViewItemClickListener;
import com.support.widget.interfacelistener.OnRecyclerViewItemLongClickListener;
import com.support.widget.layout.adapter.BaseRecyclerViewAdapter;
import com.support.widget.layout.holder.BaseViewHolder;
import com.support.widget.view.viewPager.autoscrollviewpager.AutoScrollViewPager;

import java.util.List;

/**
 * 开发者：LuoYi
 * Time: 2017 23:57 2017/4/24 04
 */

public class HomePageAdapter extends BaseRecyclerViewAdapter<HomeDataEntity, BaseViewHolder> {

    private static int HOME_ADVRTISING = 0;// 广告
    private static int HOME_TYPE_TITLE = 1;// 项目类型
    private static int HOME_PROJECT = 2;// 项目
    private static int HOME_LABEL = 3;// 标签

    public HomePageAdapter(Context context, List<HomeDataEntity> strings) {
        super(context, strings);
    }

    @Override
    protected void bindView(BaseViewHolder holder, int position, HomeDataEntity model) {
        if (holder instanceof AdvertisingHolder) {
            AdvertisingHolder advertisingHolder = (AdvertisingHolder) holder;
//            advertisingHolder.adverAsvp.
        } else if (holder instanceof TypeHolder) {
            TypeHolder typeHolder = (TypeHolder) holder;
        } else if (holder instanceof ProjectHolder) {
            ProjectHolder projectHolder = (ProjectHolder) holder;
        } else if (holder instanceof LabelHolder) {
            LabelHolder labelHolder = (LabelHolder) holder;
        }
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        if (viewType == 0) {
            view = LayoutInflater.from(mContext).inflate(R.layout.fragment_home_advertising_item, parent, false);
            return new AdvertisingHolder(mContext, view, this, getClickListener(), getLongClickListener());
        } else if (mDatas.get(viewType).getProjectType() == "1" || mDatas.get(viewType).getProjectType() == "2" || mDatas.get(viewType).getProjectType() == "3") {
            view = LayoutInflater.from(mContext).inflate(R.layout.fragment_home_item, parent, false);
            return new TypeHolder(mContext, view, this, getClickListener(), getLongClickListener());
        } else if (mDatas.size() == viewType) {
            view = LayoutInflater.from(mContext).inflate(R.layout.fragment_home_label_item, parent, false);
            return new ProjectHolder(mContext, view, this, getClickListener(), getLongClickListener());
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.fragment_project_item, parent, false);
            return new LabelHolder(mContext, view, this, getClickListener(), getLongClickListener());
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return HOME_ADVRTISING;
        } else if (mDatas.get(position).getProjectType() == "1" || mDatas.get(position).getProjectType() == "2" || mDatas.get(position).getProjectType() == "3") {
            return HOME_TYPE_TITLE;
        } else if (mDatas.size() == position) {
            return HOME_LABEL;
        } else {
            return HOME_PROJECT;
        }
    }

    /**
     * 广告
     */
    class AdvertisingHolder extends BaseViewHolder {

        public AutoScrollViewPager adverAsvp;

        public AdvertisingHolder(Context context, View rootView, RecyclerView.Adapter adapter, OnRecyclerViewItemClickListener clickListener, OnRecyclerViewItemLongClickListener longClickListener) {
            super(context, rootView, adapter, clickListener, longClickListener);
            adverAsvp = (AutoScrollViewPager) rootView.findViewById(R.id.home_adver_asvp);
        }
    }

    /**
     * 项目类型
     */
    class TypeHolder extends BaseViewHolder {

        public TypeHolder(Context context, View rootView, RecyclerView.Adapter adapter, OnRecyclerViewItemClickListener clickListener, OnRecyclerViewItemLongClickListener longClickListener) {
            super(context, rootView, adapter, clickListener, longClickListener);
        }
    }

    /**
     * 项目
     */
    class ProjectHolder extends BaseViewHolder {

        public ProjectHolder(Context context, View rootView, RecyclerView.Adapter adapter, OnRecyclerViewItemClickListener clickListener, OnRecyclerViewItemLongClickListener longClickListener) {
            super(context, rootView, adapter, clickListener, longClickListener);
        }
    }

    /**
     * 标签
     */
    class LabelHolder extends BaseViewHolder {

        public LabelHolder(Context context, View rootView, RecyclerView.Adapter adapter, OnRecyclerViewItemClickListener clickListener, OnRecyclerViewItemLongClickListener longClickListener) {
            super(context, rootView, adapter, clickListener, longClickListener);
        }
    }
}
